package com.zr.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.DetailsDao;
import com.zr.model.Content;
import com.zr.util.GetJDBCUtil;

import net.sf.json.JSONObject;

public class DetailsDaoImpl implements DetailsDao{

	GetJDBCUtil gt = new GetJDBCUtil();
	
	@Override
	public JSONObject getContentById(int cid) {
		Connection con = gt.getJDBCConnection();
		
		JSONObject jObject = new JSONObject();
		
		StringBuffer sql = new StringBuffer(""); 
		sql.append("SELECT * ");
		sql.append("FROM e_content ");
		sql.append("WHERE e_content.cid=? ");
		
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, cid);
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				
				jObject.put("content", rs.getString("ccontent"));
			}
			
			
			
			rs.close();
			pst.close();
			con.close();
		
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return jObject;
	}

}
